package pers.xuehongyan.useat.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import pers.xuehongyan.useat.server.enity.Ticket;
import pers.xuehongyan.useat.server.enity.User;
import pers.xuehongyan.useat.server.exception.user.UserNotFoundException;
import pers.xuehongyan.useat.server.manager.UserManager;
import pers.xuehongyan.useat.server.mapper.TicketMapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xuehongyan
 */
@Service
public class TicketService {
    @Resource
    TicketMapper ticketMapper;

    @Resource
    UserManager userManager;

    public Ticket getTicketById(Integer id) {
        return ticketMapper.selectById(id);
    }

    public List<Ticket> getAll(String token) throws UserNotFoundException {
        User user = userManager.getUserByToken(token);
        return getTicketByUser(user);
    }

    public List<Ticket> getTicketByUser(User user) {
        return ticketMapper.selectList(new QueryWrapper<Ticket>().eq("user_id", user.getId()));
    }
}
